import java.util.Stack;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-08-01
 * Time: 20:13
 */
public class Test {
    public boolean isValid(String s) {
        if(s.length() % 2 != 0) return false;
        Stack<Character> stack = new Stack<>();
        for(int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(ch == '(' || ch == '{' || ch == '[') {
                stack.push(ch);
            }else {
                if(!stack.empty()) {
                    char tmp = stack.pop();
                    if(ch == ')' && tmp != '(' || ch == '}' && tmp != '{' || ch == ']' && tmp != '[')
                        return false;
                }else {
                    return false;
                }
            }
        }
        if(stack.empty()) {
            return true;
        }
        return false;
    }

}

class MinStack {
    public Stack<Integer> stack;
    public Stack<Integer> minStack;
    public MinStack() {
        this.stack = new Stack<>();
        this.minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minStack.empty() || val <= minStack.peek()) {
            minStack.push(val);
        }
    }

    public void pop() {
        Integer tmp = stack.pop();
        if(tmp.compareTo(minStack.peek()) == 0) {
            minStack.pop();
        }
    }

    public int top() {
        if(!stack.empty()) {
            return stack.peek();
        }

        return Integer.MIN_VALUE;
    }

    public int getMin() {
        if(!minStack.empty()) {
            return minStack.peek();
        }

        return Integer.MAX_VALUE;
    }
}
